﻿using Beetle;
using System;
using System.Text;

internal class Class_aj : Attribute
{
    private byte[] _field_a = new byte[TcpUtils.StringEncodingLength];
    private char[] _field_b = new char[TcpUtils.StringEncodingLength];
    private ByteArraySegment _field_c = new ByteArraySegment();
    private int _field_d;

    public string a(byte[] A_0, int A_1, int A_2, Encoding A_3)
    {
        string str;
        try
        {
            int length = A_3.GetChars(A_0, A_1, A_2, this._field_b, 0);
            str = new string(this._field_b, 0, length);
        }
        catch (Exception exception)
        {
            throw NetTcpException.StringDecodingError(exception);
        }
        return str;
    }

    public void a(string A_0, Encoding A_1, Class_b A_2, BufferWriter A_3, bool A_4)
    {
        try
        {
            if (!A_3.EnabledVariant && A_2.c((A_0.Length * 2) + 4))
            {
                int dstOffset = A_2._field_g;
                if (A_4)
                {
                    A_2._field_g += 4;
                    A_2._field_h += 4;
                    A_3._field_e += 4;
                }
                this._field_d = A_1.GetBytes(A_0, 0, A_0.Length, A_2._field_e, A_2._field_g);
                A_2._field_g += this._field_d;
                A_2._field_h += this._field_d;
                A_3._field_e += this._field_d;
                if (A_4)
                {
                    Buffer.BlockCopy(A_3._field_g.GetBytes(this._field_d), 0, A_2._field_e, dstOffset, 4);
                }
            }
            else
            {
                this._field_d = A_1.GetBytes(A_0, 0, A_0.Length, this._field_a, 0);
                if (A_4)
                {
                    A_3.Write(this._field_d);
                }
                A_3.Write(this._field_a, 0, this._field_d);
            }
        }
        catch (Exception exception)
        {
            throw NetTcpException.StringEncodingError(exception);
        }
    }

    public void b(string A_0, Encoding A_1, Class_b A_2, BufferWriter A_3, bool A_4)
    {
        try
        {
            if (!A_3.EnabledVariant && A_2.c((A_0.Length * 2) + 2))
            {
                int dstOffset = A_2._field_g;
                if (A_4)
                {
                    A_2._field_g += 2;
                    A_2._field_h += 2;
                    A_3._field_e += 2;
                }
                this._field_d = A_1.GetBytes(A_0, 0, A_0.Length, A_2._field_e, A_2._field_g);
                A_2._field_g += this._field_d;
                A_2._field_h += this._field_d;
                A_3._field_e += this._field_d;
                if (A_4)
                {
                    Buffer.BlockCopy(A_3._field_g.GetBytes((ushort) this._field_d), 0, A_2._field_e, dstOffset, 2);
                }
            }
            else
            {
                this._field_d = A_1.GetBytes(A_0, 0, A_0.Length, this._field_a, 0);
                if (A_4)
                {
                    A_3.Write((ushort) this._field_d);
                }
                A_3.Write(this._field_a, 0, this._field_d);
            }
        }
        catch (Exception exception)
        {
            throw NetTcpException.StringEncodingError(exception);
        }
    }
}

